package com.xyw.code.platform.webapps.rest;


import com.xyw.code.common.core.entity.vo.Result;
import com.xyw.code.platform.common.entity.enums.CommonStatusEnum;
import com.xyw.code.platform.common.entity.po.SysJob;
import com.xyw.code.platform.webapps.log.SysLog;
import com.xyw.code.platform.webapps.service.ISysJobService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 岗位管理 前端控制器
 * </p>
 *
 * @author xyw
 * @since 2020-02-07
 */
@Api(value="岗位模块")
@RestController
@RequestMapping("/sysJob")
public class SysJobController {

    @Autowired
    private ISysJobService jobService;

    @GetMapping("/getByDeptId/{deptId}")
    @ApiOperation(value = "根据部门id得到岗位",notes = "根据部门id得到岗位")
    public Result<List<SysJob>> getByDeptId(@PathVariable("deptId") String deptId) {
        return Result.success(jobService.queryByDeptId(deptId));
    }

    /**
     * 获取岗位列表
     * @param page
     * @param pageSize
     * @param jobName
     * @return
     */
    @GetMapping("/query")
    @ApiOperation(value = "获取岗位列表",notes = "获取岗位列表")
    public Result query(Integer page, Integer pageSize,@RequestParam(defaultValue = "") String jobName) {
        return Result.success(jobService.query(page, pageSize, jobName));
    }

    /**
     * 保存岗位
     *
     * @param sysJob
     * @return
     */
    @PostMapping("/add")
    @ApiOperation(value = "新增岗位",notes = "新增岗位")
    public Result add(@RequestBody SysJob sysJob) {
        sysJob.setDelFlag(CommonStatusEnum.NORMAL.getType());
        return Result.success(jobService.save(sysJob));
    }

    /**
     * 更新岗位
     * @param sysJob
     * @return
     */
    @PutMapping("/update")
    @ApiOperation(value = "更新岗位",notes = "更新岗位")
    @SysLog(descrption = "更新岗位")
    public Result update(@RequestBody SysJob sysJob) {
        return Result.success(jobService.updateById(sysJob));
    }

    /**
     * 根据id删除岗位
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除岗位",notes = "删除岗位")
    public Result delete(@PathVariable("id") String id) {
        SysJob job = new SysJob();
        job.setId(id);
        job.setDelFlag(CommonStatusEnum.DELETE.getType());
        return Result.success(jobService.updateById(job));
    }
}

